﻿<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Cwjk_Cwzt_Edit.aspx.vb"
	Inherits="PubProject.Cwjk_Cwzt_Edit" %>
<%@ Register TagPrefix="cnt" Namespace="Mysoft.Map.Application.Controls" Assembly="Mysoft.Map.Application.Components" %>
<%@ Register TagPrefix="mnu" Namespace="Mysoft.Map.Application.Menus" Assembly="Mysoft.Map.Application.Components" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
	<title>新增账套</title>
	<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
	<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
	<meta name="vs_defaultClientScript" content="JavaScript">
	<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
	<link rel="stylesheet" type="text/css" href="/_nav/menu.css">
	<link rel="stylesheet" type="text/css" href="/_common/styles/global.css">
	<link rel="stylesheet" type="text/css" href="/_grid/map_grid.css">
	<link rel="stylesheet" type="text/css" href="/_forms/styles/form.css">
	<link rel="stylesheet" type="text/css" href="/_nav/tabs.css">
	<link rel="stylesheet" type="text/css" href="/_nav/nav.css">
	<link rel="stylesheet" type="text/css" href="/_common/styles/select.css">   
	<script language="javascript" src="/_controls/settings.aspx"></script>	  
	<script language="javascript" src="/_controls/setting.js"></script>	  
	<script language="javascript" src="/_controls/util/util.js"></script> 
	<script language="javascript" src="/_controls/datetime/date.js"></script> 
	<script language="javascript" src="/_controls/datetime/time.js"></script>   
	<script language="javascript" src="/_controls/number/number.js"></script>    
	<script language="javascript" src="/_nav/menu.js"></script>		 
	<script language="javascript" src="/_common/scripts/global.js"></script>  
	<script language="javascript" src="/slxt/js/Public.js"></script>  
	<script language="javascript" src="/PubProject/js/Public.js"></script> 
	<script language="javascript" src="/PubProject/js/jquery.js"></script>

	<script language="javascript">
		//在线帮助文件
	    var _MyHelpfile = "/Cbgl/HELP/topics/财务人员/设置财务接口/设置账套/新增账套.html";
		var strOldIsPost;
		// 初始化界面
		function window.onload() {
		   
			if (document.all.SoftVesionGUID[0].value && document.all.SoftVesionGUID[0].value != "" && document.all.SoftFileTypeGUID[0].value && document.all.SoftFileTypeGUID[0].value != "") {
		        SetSoftFileTypeGUID(document.all.SoftVesionGUID[0].value, document.all.SoftFileTypeGUID[0].value);
			}

			HideShowElementZt();

			if (appForm.SoftFileTypeGUID != undefined && appForm.SoftFileTypeGUID != null && appForm.SoftFileTypeGUID.value == "XML 同步传输") {
				HideShowElement("WebServiceAddr", "textHasIcon", "");
				appForm.WebServiceAddr.setReadOnly(false);
				//SetControlReq(appForm.WebServiceAddr, true);
			}
			else {
				HideShowElement("WebServiceAddr", "textHasIcon", "none");
				appForm.WebServiceAddr.setReadOnly(true);
				//SetControlReq(appForm.WebServiceAddr, false);
			}
			if (__type.value == 1) {
				document.all("SaveTr").style.display = "";
			}

			if (__type.value == 2) {
				strOldIsPost = appForm.IsPOS.value;
				document.all("SaveTr").style.display = "none";
				var oTable = document.all("Section1");				
				var rows = oTable.rows;
				if (rows.length > 0) {
					rows[0].style.display = "none";
					rows[1].style.display = "none";
				}
				$('#areaForm').removeClass("main");
				 
			}
            
            
			if (document.all("__Application") && document.all("__Application").value == "0101") {
			    _MyHelpfile = "/Slxt/HELP/topics/财务管理/财务接口设置/账套设置.html";
			}
		}

		function SaveInfo() {	 
			$('#save').click()
		}
		//保存数据
		function Save() {
			appForm.Save();
		}

		//验证appForm的值是否正确
		function CheckAppFromValue() {	 
			if (appForm.Application.value == "") {
				return false;
			}

			if (appForm.BUGUID.value == "") {
				return false;
			}

			if (appForm.CwztName.value != "" && appForm.CwztName.value != appForm.appForm_CwztName_Old.value) {
				//判断账套名称是否重复
				var sPath = "/PubProject/Cwjk/Cwjk_XMLHTTP.aspx?BUGUID=" + escape(appForm.BUGUID.value) + "&Application=" + escape(appForm.Application.value) + "&CwztName=" + escape(appForm.CwztName.value);

				var sResults = openXMLHTTP(sPath, "CheckCwztNameIsRepeated");

				if (sResults.split('|')[0] == "YES") {
					alert("账套名称重复，请重新录入！");
					appForm.CwztName.focus();
					return false;
				}
			}

			return true;
		}

		//保存前调用的方法
		function oprBeforeSave() {
		 
			var bCheckResult = CheckAppFromValue();
			event.returnValue = bCheckResult;
			if (!bCheckResult) return;
		 
			if (appForm.SoftVesionGUID.value == "金蝶 EAS 6.0") {
				appForm.NCCode.setValue("");
				appForm.NCBUName.setValue("");
				appForm.WebServiceAddr.setValue("");
			}
			else if (appForm.SoftVesionGUID.value == "用友 NC 5.5") {
			    appForm.KingDeeCode.setValue("");    
				if (appForm.SoftFileTypeGUID.value == "XML 下载") {
					appForm.WebServiceAddr.setValue("");
				}
			}
			else {
				appForm.NCCode.setValue("");
				appForm.KingDeeCode.setValue("");
				appForm.NCBUName.setValue("");
				appForm.WebServiceAddr.setValue("");
			}
			if (__mode.value == 2) {
				var strIsPos = appForm.IsPOS.value;
				if (strOldIsPost != strIsPos) {
					appForm.userxml = "<items><item IsChangeIsPost='1' OldIsPOS='" + strOldIsPost + "' ></item></items>"
					if (strIsPos == 1) {
						if (confirm("“是否存在POS机费用”选项发生调整，将会新增“POS机”的分录规则，确定保存吗？") == true) {
						}
						else {
							event.returnValue = false;
							return false;
						}
					}
					else {
						if (confirm("“是否存在POS机费用”选项发生调整，将会删除“POS机”的分录规则，确定保存吗？") == true) {
						}
						else {
							event.returnValue = false;
							return false;
						}
					}		 
				}
				else {
					appForm.userxml = "<items><item IsChangeIsPost='0' OldIsPOS='" + strOldIsPost + "' ></item></items>"
				}
			}
			 
			appForm.BuildXml();
		}

		//保存后调用的方法
		function oprAfterSave() {
			var xmlDom = new ActiveXObject("Microsoft.XMLDOM")	 
			try {
				xmlDom.loadXML(appForm.returnxml);

				if (xmlDom.documentElement.attributes.getNamedItem("result").value == "true") {	 
					//保存成功后的相关操作					
					var oldCwztName = appForm.appForm_CwztName_Old.value;
					appForm.appForm_CwztName_Old.value = appForm.CwztName.value;

					var sOid = xmlDom.documentElement.attributes.getNamedItem("keyvalue").value;
					if (__type.value == 1) {
						window.opener.RefreshByCwztGUID(sOid);
						window.close();
					} else {
					strOldIsPost = appForm.IsPOS.value;
						if (oldCwztName != appForm.CwztName.value) {
							parent.parent.RefreshByCwztGUID(sOid);
						}
					}
				}

				event.returnValue = true;
			}
			catch (e) {
				alert("返回的xml格式错误，请与管理员联系！");
				return;
			}
		}

		// 测试 Web Service
		function openWebServiceWin() {
			if (appForm.WebServiceAddr.value == "") {
				alert("请先输入Web Service地址！");
				appForm.WebServiceAddr.focus();
				return;
			}
			else {
				var sWebServiceAddr = appForm.WebServiceAddr.value;

				var sPath = "/PubProject/Cwjk/Cwjk_XMLHTTP.aspx?WebServiceAddr=" + escape(sWebServiceAddr);
				var sResults = openXMLHTTP(sPath, "CheckWebServiceIsConnective");

				if (sResults.split('|')[0] == "YES") {
					alert("Web Service服务链接成功！");
				}
				else {
					alert("Web Service服务链接失败，请检查地址是否正确！");
				}
			}
		}

		//接口类型发生变更时调用的方法
		function ChangeSoftFileType(obj) {
			HideShowElementZt();
			if (obj.value == "XML 同步传输") {
				HideShowElement("WebServiceAddr", "textHasIcon", "");
				appForm.WebServiceAddr.setReadOnly(false);
				//SetControlReq(appForm.WebServiceAddr, true);
			}
			else {
				HideShowElement("WebServiceAddr", "textHasIcon", "none");
				appForm.WebServiceAddr.setReadOnly(true);
				//SetControlReq(appForm.WebServiceAddr, false);
			}
		}

		//财务软件版本发生变更事件时调用的方法
		function ChangeSoftVesion(sSoftVesionGUID) {    
			SetSoftFileTypeGUID(sSoftVesionGUID);	 
			ChangeSoftFileType(appForm.SoftFileTypeGUID);
		}

		//显示或隐藏控件
		function HideShowElementZt() {
			if (appForm.SoftVesionGUID.value == "金蝶 EAS 6.0") {
				HideShowElement("NCCode", "text", "none");
				HideShowElement("NCBUName", "text", "none");
				HideShowElement("KingDeeCode", "text", "");

			}
			else if (appForm.SoftVesionGUID.value == "用友 NC 5.5") {
				HideShowElement("NCCode", "text", "");
				HideShowElement("NCBUName", "text", "");
				HideShowElement("KingDeeCode", "text", "none");
			}
			else {
				HideShowElement("NCCode", "text", "none");
				HideShowElement("NCBUName", "text", "none");
				HideShowElement("KingDeeCode", "text", "none");
			}
		}

		//根据 SoftVesionGUID 设定相关的 SoftFileType
		function SetSoftFileTypeGUID(sSoftVesionGUID, sInitValue) {
			var sXML = "";
			var sResults = "";
			var sInitValue = sInitValue;

			var sPath = "/PubProject/Cwjk/Cwjk_XMLHTTP.aspx?SoftVesionGUID=" + escape(sSoftVesionGUID);

			sResults = openXMLHTTP(sPath, "GetSoftFileTypeBySoftVesionGUID");

			if (sResults.split('|')[0] == "YES") {
				sXML = sResults.split('|')[1];
			}
			else {
				sXML = "<items><item text=\"\" value=\"\" /></items>";
			}    
 
			RefreshDLLItem("SoftFileTypeGUID", sXML, sInitValue);
		}
	</script>

</head>
<body ms_positioning="GridLayout">
	<table class="layout" cellspacing="0" cellpadding="0">
		<colgroup>
			<col width="140">
			<!-- 导航菜单：140px -->
			<col>
		</colgroup>
		<tr height="48" id="trzc" style="display: none">
			<td colspan="2">
				<!-- 菜单 -->
				<mnu:AppFormMenu ID="appFormMenu" runat="server"></mnu:AppFormMenu>
			</td>
		</tr>
		<tr>
			<td colspan="2" id="tdAreas">
				<div class="main" id="areaForm">
					<cnt:AppForm ID="appForm" runat="server" DefaultValueXml="" ProcessType="xmlhttp"
						Assembly="Mysoft.Map.Core" InvokeClass="Mysoft.Map.Data.MyDB" InvokeFunction="SaveXml"
						OnBeforeSave="oprBeforeSave()" OnAfterSave="oprAfterSave()">
					</cnt:AppForm>
				</div>
			</td>
		</tr>
		<tr id="SaveTr" style="display:none">
			<td class="buttons" style="height: 40px" colspan="2">
				<button onclick="$('#save').click()">
					保存</button>&nbsp;&nbsp;
				<button onclick="window.close();">
					关闭</button>
			</td>
		</tr>
	</table>
	<form id="Form1" runat="server">
	</form>
</body>
</html>
